package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpCollectProductSplitLogBo;
import com.erp.gather.domain.vo.ErpCollectProductSplitLogVo;
import com.erp.gather.service.IErpCollectProductSplitLogService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 采集商品拆分日志
 *
 * @author erp
 * @date 2023-07-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/collectProductSplitLog")
public class ErpCollectProductSplitLogController extends BaseController {

    private final IErpCollectProductSplitLogService iErpCollectProductSplitLogService;

    /**
     * 查询采集商品拆分日志列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpCollectProductSplitLogVo> list(ErpCollectProductSplitLogBo bo, PageQuery pageQuery) {
        return iErpCollectProductSplitLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取采集商品拆分日志详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpCollectProductSplitLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpCollectProductSplitLogService.queryById(id));
    }

    /**
     * 新增采集商品拆分日志
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpCollectProductSplitLogBo bo) {
        return toAjax(iErpCollectProductSplitLogService.insertByBo(bo));
    }

    /**
     * 修改采集商品拆分日志
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCollectProductSplitLogBo bo) {
        return toAjax(iErpCollectProductSplitLogService.updateByBo(bo));
    }

    /**
     * 删除采集商品拆分日志
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpCollectProductSplitLogService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
